home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / srefv112.zip / SREFPRC1.DOC < prev    next >
Text File  |  1996-05-25  |  17KB  |  374 lines

  1. SRE-FILTER ver 1.11 Documentation: SREFPRC1.RXL procedure library. 5/24/96
  2.  
  3.  
  4. SRE-Filter uses "macrospace" to store many of it's procedures, and also
  5. as a cache for user-configurable input files.  These procedures are
  6. stored in a "macrospace library file" called SREFPRC1.RXL.  When
  7. SRE-FILTER is first run (that is, when GoServe is started, and the first
  8. request arrives), SRE-FILTER will load this library into macrospace.
  9.  
  10. Procedures stored in macrospace are available to all OS/2 programs, including
  11. routines written by ambitious REXX programmers (say, to be used to respond
  12. server side processing requests).  Even more ambitious programmers may want 
  13. to modify the source code for these procedures!
  14.  
  15. The source code for these procedures consists of a number of files with
  16. the extention .SRF; all stored in the SREFPRC1.ZIP file.  In addition, 
  17. SREFPRC1.ZIP contains MAKELIB.CMD,which  is used to create the 
  18. SREFPRC1.RXL "macrospace library" from these procedures. 
  19. To work with macrospace, you can use MSPACE.CMD (also in SREFPRC1.ZIP).
  20. Enter MSPACE ? for instructions on how to use MSPACE.CMD.
  21.  
  22.  
  23. -------         ----------          ---------          ------------
  24.  
  25. The following describes most of the procedures contained in SREFPRC1.  
  26. If you area serious programmer, you may want to look at the source
  27. code (contained in  various .SRF files) for further descriptions.
  28.  
  29. Note that SREFPRC1.RXL is "loaded" into macrospace by SRE-FILTER, which
  30. uses procedures in REXXLIB.DLL.
  31.  
  32. -------         ----------          ---------          ------------
  33. -------         ----------          ---------          ------------
  34.  
  35. SREF_OPEN_READ: Open a file for read/write (and wait if it's currently locked)
  36. Usage: open_time=sref_open_read(afile ,seconds_to_try_for , howopen )
  37.         afile: file to open
  38.      seconds_to_try_for : seconds to try for
  39.         howopen: BOTH= open as read/write
  40.                  WRITE= open as write
  41.                  NEW = open as write, must not already exist
  42.                  READ = open as read
  43. Returns:
  44.  -2 : Timed out
  45.  -1 : File does not exist, or does exist (if howopen=WRITE)
  46.  >0 : Seconds it took (minimum value of 0.01) to open
  47.  
  48. -------         ----------          ---------          ------------
  49.  
  50. SREF_GRAB_FILE: Read a file, and return it (and wait if it's currently locked)
  51. Usage:   afile_string=sref_grab_file(afile,seconds_to_try_for)
  52.                (see descriptions above)
  53.  
  54. Returns:
  55.    If file exists/is accessible, returns the file (complete with all
  56. CRLF's etc.). If file does not exist/ is not accessible, returns a 0.
  57.  
  58. -------         ----------          ---------          ------------
  59.  
  60. SREF_REPLACESTRG: Replace substrings
  61. Usage: newstring=sref_replacestr(haystack,needle,replacement, type , exactmatch)
  62.         haystack: The string to search in
  63.         needle: The string to search for
  64.      replacement: Replace occurences of "needle" with "replacement"
  65.           type: 
  66.                 FORWARD: Replace first occurence
  67.                BACKWARD: Start from end, replace "last" occurence.
  68.                     ALL: Replace all occurences
  69.     exactmatch:  if YES, then cases must match (NO=case is ignored).
  70.                   Note that the case of the "replacement" is retained, regardless
  71.                   of the value of exactmatch.
  72.  
  73. Returns:
  74.      The haystack,with the replacements (if no replacements, return the
  75.      original value of haystack)
  76.  
  77. -------         ----------          ---------          ------------
  78.  
  79.  
  80. SREF_MEDIATYPE :  Returns mime type of a file
  81. Usage: mimetype=sref_mediatype(filename)
  82. Comment: uses the extension of filename to determine the mime type.
  83. For example, AA.HTM would yielld "text/html".
  84.  
  85. -------         ----------          ---------          ------------
  86.  
  87.  
  88. SREF_HOST: A "host lookup"
  89. Usage:  aresult=sref_host(ipaddress)
  90.         IPaddress can be numeric or character (with appropriate periods)
  91. Aresult is a sentence noting the ipaddress and the name associated with it.
  92.  
  93. -------         ----------          ---------          ------------
  94.  
  95.  
  96. SREF_LOOKUP_COUNT : Augment a SRE-FILTER "counter file"
  97. usage: newcount=sref_lookup_count(ctfile, needle, augment , substring , noadd)
  98.                 ctfile: Name of the "counter file" to examine 
  99.                         Should have a format like: Aneedle  ACountT  optional info
  100.                 needle: The target of the search
  101.                 augment:  YES: augment the count
  102.                           ADD: augment the count, or if needle can not be found,
  103.                            add new entry with count=1
  104.                 substring: EXACT: Exact match only
  105.                                *: Use wildcard match if no exact match
  106.                           ABBREV: Use abbreviation match if no exact match
  107.                 noadd:     1: just return matching filename and message
  108.                                 (do NOT lookup count or augment)
  109.                            2: save the date along with action and count
  110.  
  111. Returns a space delimited list containing STATUS COUNT Message-String
  112.      If status=0, then some failure, 1 then success,
  113.      2 then no match, but we added it (only possible if AUGMENT used)
  114.  
  115. -------         ----------          ---------          ------------
  116.  
  117.  
  118. SREF_EXTRACT_BLOCK : Extract a "labeled block" from a string.
  119. Usage: ablock=sref_extract_block(haystack , alabel , delim1  , delim2  , delim3)
  120.  
  121.  Extract a block from haystack, defined by a Labeled block,
  122.   where the label has the form delim1 label delim2 multi-line_string delim3  xxx
  123.  Default values of delim1={,  2=}  3={
  124.  Note that labels must have NO embedded spaces.
  125.  
  126. -------         ----------          ---------          ------------
  127.  
  128.  
  129. SREF_INSERT_BLOCK : Insert a block into a string, at a "labeled" location.
  130. Usage: newhaystack=sref_insert_bloc(haystack,alabel,add_string,after,delim1,delim2)
  131.  
  132.    Insert a add_string into haystack, right  after or before aLabel.
  133.      where the alabel has the form delim1 label delim2
  134.    Insertion is immediately after delim2, or before delim1
  135.    (if after=1, then after)
  136.    Default values of delim1={,  2=}
  137.    Note that labels must have NO embedded spaces.
  138.  
  139. Returns the added to (or not added to) haystack
  140.  
  141. -------         ----------          ---------          ------------
  142.  
  143. SREF_MAKE_BLOCK  : Replaces substrings with other substrings.
  144. Usage: newhaystack=sref_make_block(needle, haystack, delim1 , delim2, check_case)
  145.  
  146.       Replace all occurences of NEEDLE in HAYSTACK with delim1 needle delim2.
  147.       If delim1 and delim2 not give, then { AND } are used.
  148.       Example: make_block(boys,' there are wild boys out there','<b>',' </b>')
  149.            returns 'there are wild <b>boys </b> out  there'
  150.            (note that spaces are all retained).
  151.       IF check_case=1, then cases must match (between needle and haystack)
  152.  
  153. -------         ----------          ---------          ------------
  154.  
  155. SREF_FIX_URL  : Creates a proper HTTP URL.
  156. Usage:  newurl=sref_fix_url(local_url,servername,serverport)
  157.  
  158. The newurl will contain the http://, servername and port, and local_url.
  159.  
  160.  
  161. -------         ----------          ---------          ------------
  162.  
  163. SREF_GET_URL  : Retrieves a  HTTP URL.
  164. Usage:  newurl=sref_fix_url(url,maxchar)
  165.  
  166. Will do socket calls to "GET" a URL. Will get first MAXCHAR
  167. characters; if MAXCHAR is missing, get first 10million (ie. all)
  168. characters. 
  169. Returns 0 if any problem -- also SAYs stuff.
  170.  
  171. -------         ----------          ---------          ------------
  172.  
  173. SREF_DO_VIRTUAL: Convert a url into an absolute file.
  174. Usage: absolute_filename=sref_do_virtual(defdir,url_name,mok,virtual_file)
  175.              defdir: Default drive:directory to use
  176.              rel_name:  A url (of the form /A1/A1/FILE.EXT) to
  177.                           convert to an absolute file name.
  178.              mok:   If 1, then look in macrospace for a "cached" version
  179.                         of virtual_file (see sref_load_mac for details)
  180.             virtual_file: File containing virtual directory entries
  181. Returns: File name (with drive/directory) or 0 if virtual directory
  182.         information (virtual_file) not found.  Note that even if the
  183.         virtual_file is not used, failure to find it will cause a 0
  184.         to be returned (if it is found, but not used, the defdir is used
  185.         to build absolute_filename)
  186.  
  187. -------         ----------          ---------          ------------
  188.  
  189. SREF_WILDCARD  : Do a wildcard match (with substitution)
  190. Usage:  newstring=sref_wildcard(original, target replacement)
  191.  
  192. See if target matches original.  Target can contain *, which are
  193. used as wildcard characters (as with matching file names in OS/2).
  194. If a match occurs, the replacement is returned, possibly with
  195. "substitution" matches  -- i.e.; the part of original "covered by" the
  196. * in the target is placed in the replacement
  197.  
  198. Example:  newstring=sref_wildcard('1234567','12*67 abcde*f',0)
  199.           yields:  newstring= abcde345f
  200.  
  201. -------         ----------          ---------          ------------
  202.  
  203.  
  204. SREF_JULDATE  : Returns julian date (since  1/1/0000) and fractional time
  205. Usage:  juldate=sref_juldate(mode, time_string)
  206.                 mode: F: Date/time is: yy/mm/dd/hh/mm/ss mode (
  207.                           as returned by sysfiletree(afile,'stem','FT')
  208.                       T: Date/time is: yyyymmdd hr : mm : sec
  209.                           as returned by: adate=date('S')|| ' '||time()
  210. Typical return: 729152.125 ; with the fraction accurate to about 1 minute.
  211.  
  212. -------         ----------          ---------          ------------
  213.  
  214.  
  215. SREF_LOAD_MAC  : Cache "user-configurable input files" into macrospace
  216.  
  217. Usage: status=sref_load__mac(tempdir,user_File,initfilt_file,repstrgs_File,  ,
  218.             alias_file,interpret_file,virtual_file,access_file,whichone)
  219.  
  220.    Tempdir: working directory (this creates temporary files)
  221.    user_file..Access_file: SRE-FILTER's user-configurable input files.
  222.    If whichone=0, load all files
  223.      Else, choose one of: REPSTRGS INITFILT USER ALIAS INTERPRET VIRTUAL ACCESS
  224.  
  225.    If whichone=0, then update always.
  226.    Otherwise, update (just the whichone) only if macrospace version is older
  227.    then the file version.
  228.  
  229. Note that a creation date/time is stored with the "text".
  230. This assumes that macrospace_input =1 (that storage in macrospace is desired).
  231.  
  232. Returns 1 if an update occured, otherwise 0.
  233.  
  234. -------         ----------          ---------          ------------
  235.  
  236.         
  237. SREF_VERSION  : Returns string listing the SRE-FILTER version
  238. Usage: filter_name=sref_version()
  239.  
  240. Sample return: SRE-FILTER Ver 1.1 5 May 1996
  241.       (the date is the date this was called)
  242.  
  243. -------         ----------          ---------          ------------
  244.  
  245.  
  246. SREF_CONJUREF : Create/delete temporary files
  247. Usage: newfiles=conjuref(basedir,basenames,extlist,minfree,mintime)
  248.  
  249.         basedir: directory to clean up (if > 10 files,
  250.               remove all files > mintime hours old)
  251.         basenames: list of (up to 4-char) file-stems to be used
  252.                  (a random element will be added)
  253.         extlist: list of up to 10 extension to be added to this file-stems
  254.  
  255.      So, if base= ZDOG,ZMOM and EXTLIST is FOO,CAT,001 then this will create
  256.      ZDOGxxxx.FOO, ZMOMxxxx.CAT and ZMOMxxxx.001, where xxxx is some 4 digit
  257.     random # (guaranteed to cause unique file names to be selected) 
  258.     (note replication to generate as many names as longest list)
  259.  
  260.        minfree: Try to get this much space free by deleting files 
  261.                 from basedir (in kb)
  262.        mintime: But don't delete anything less than this hours old
  263.  
  264. Return:   If newfiles=0, then could not create (say, minfree was violated)
  265.           Else, comma delimited list of file names 
  266.                 that can be used as temporary files.
  267.  
  268. CAUTION: Be careful what you choose as your basedir (you could automatically
  269. delete important stuff if your basedir is not strictly a "temporary files"
  270. directory).
  271.  
  272. -------         ----------          ---------          ------------
  273.  
  274.  
  275. SREF_CHK_PRIV : Check user file to see if a "logged on" client has a privilege
  276. Usage:  gotit=sref_chk_priv(targclass,privset0,user_file)
  277.               Target: The privilege to check for.
  278.               Privset0: Currently available privilegs (perhaps automatically
  279.                         granted at logon)
  280.               user_file: File containing username, password, and privileges
  281.                         information.
  282.  
  283.   This first  checks the "current" privileges (PRIVSET0).  If TARGET is 
  284.   not found therein, then...
  285.       ... the client may never have "logged on", and may have an account
  286.        .  containing additional "privileges".
  287.       So, give them an opportunity to "explicitily logon" (and obtain these additional
  288.       privileges).
  289.  
  290. Return:
  291.     If privilege exists (in privset0 or from a privilige obtained by explicitily
  292.     logging on), RETURN 1.
  293.  
  294.     Otherwise, RETURN 0
  295.  
  296.  Special case: if Targets= 0, 
  297.           just return the "explicitily logon obtained" privileges
  298.           should be called as newpriv=sref_chk_priv(0,0,userfile)
  299.  
  300. -------         ----------          ---------          ------------
  301.  
  302.  
  303. SREF_MAILIT :  Use REXX socket calls to send e-mail
  304. Usage: status=mailit(address_list,messagesmtp_gateway,sender_address)
  305.               address_list: A space delimited list of addresses
  306.                    message: A message string, that may contain CRLFs
  307.                           (and may be rather long)
  308.              smtp_gateway: The IP address of your SMTP server
  309.            sender_address: The sender's address (optional)
  310.                If sender's address is not given, it will be generated using
  311.                GoServe's servername() function.
  312.   Examples:
  313.        status=mailit("BOB@HIS.NET" , "This is my message ", "MAIL.MY.ORG" )
  314.        status= mailit("BOB@HIS.NET JILL@HER.COM " , "This is my message ", ,
  315.                     "MAIL.MY.ORG", "HARRY@MY.ORG")
  316.  
  317.   Note on recipient addresses:
  318.      The message will be sent to each address.  Since the addresses are
  319.      sent and then the message, this allows for fairly rapid mailing to multiple
  320.      individuals.
  321.  
  322. -------         ----------          ---------          ------------
  323. SREF_NEW_GMT: Compute a new GMT time, given a date,time,and offset
  324.  
  325. usage new_gmt_time=sref_new_gmt(frac_day,adate,asec)
  326.  
  327. Frac_day =fraction of a day to add to adate and asec (default=0)
  328. adate  is a date in 'base date' format, default is date when called
  329.         (i.e.; date('b')
  330. asec is a second in day, default is time when called (i.e.; time('s')
  331.  
  332.  
  333. -------         ----------          ---------          ------------
  334. SREF_EXPIRE_RESPONSE: Build a response header that does not have an
  335. immediate expiration.
  336. Usage: foo=sref_expire_respons(aoffset,alength,atype,noauto)
  337.    aoffset is fraction of day to add to current date/time. This will
  338.      be converted to gmt (assuming gmt variables have been set, as described
  339.      in goserve.doc). If aoffset<0, then an "expires" header will Not
  340.      be written.  Default is 0.04
  341.  
  342.    alength is the size of the document being sent. Default is 0
  343.    atype is the mime type. Default is text/html
  344.    noauto= Y or N: If Y, or if missing, then suppress auto - headers.
  345.            
  346.  
  347. This is meant to be used when the default response headers are inappropriate.
  348. For example, if returing a file with server side includes (say, using FILE ERASE
  349. or VAR), GoServe will always give an "immediate" expiration time.  This can
  350. aggravate clients with browsers that reload the document when the document
  351. is "backed up" to.  By giving a small aoffset (say, 0.02), most of this
  352. can be avoided (assuming that the document being sent to the client
  353. does not need minute-by-minute updating!)
  354.  
  355. Note that if noauto=N, we HIGHLY recommend using a 'HEADER NOAUTO' statement
  356. somewhere before this call. If you do not have such a line, the GoServe
  357. default headers, and the headers generated here, will be sent.  Very confusing!
  358.  
  359.  
  360. -------         ----------          ---------          ------------
  361. -------         ----------          ---------          ------------
  362.  
  363. Citations:  
  364.  
  365. SRE-FILTER uses the macrospace manipulation routines
  366. that come with the REXXLIB library.  REXXLIB is shareware that can
  367. be found at HOBBES.NMSU.EDU (try the OS2/DEV32/REXX directory) ,or 
  368. directly from www.quercus-sys.com/rexxlib.htm.
  369.  
  370. SREF_MAILIT is a modification of a routine written by Dave Briccetti.
  371.  
  372. SREF_GET_URL is adapted from MOVEAUD.CMD, that comes with GoServe.
  373.  
  374.